package com.epam.OOP.transport;

import com.epam.OOP.cargo.Cargo;
import com.epam.OOP.utils.BundlesReader;
import com.epam.OOP.utils.PropertiesReader;
import com.epam.OOP.utils.Validator;

import java.io.UnsupportedEncodingException;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * User: Yelena_M
 * Date: 05.08.13
 * Time: 0:24
 * To change this template use File | Settings | File Templates.
 */
public class VolumeChecker {

    private static PropertiesReader propertiesReader = new PropertiesReader();

    public static int transportVolumeCount() throws UnsupportedEncodingException {
        int vanVolume;

        vanVolume = Van.realVanVolumeCount(
                Integer.parseInt(propertiesReader.getProperties("lengthPlace")),
                Integer.parseInt(propertiesReader.getProperties("widthPlace")),
                Integer.parseInt(propertiesReader.getProperties("heightPlace")));
        System.out.println(BundlesReader.read("MessageTransportVolume") + " " + vanVolume);
        return vanVolume;
    }

    public static int cargoVolumeCount(Set<Cargo> cargos) throws UnsupportedEncodingException {
        int cargoVolume = 0;
        for(Cargo c : cargos){
            if (Validator.checkDataForDigital(String.valueOf(c.getVolume()))) {
                cargoVolume += c.getVolume();
            } else {
                BundlesReader.read("MessageWrongData");
                System.exit(0);
            }
        }
        System.out.println(BundlesReader.read("MessageCargoVolume") + " " + cargoVolume);
        return cargoVolume;
    }
}
